package io.kimmking.dubbo.demo.second.provider.service.nettycharroom;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.kimmking.common.rocketmq.repository.ProducerWrapper;
import io.kimmking.dubbo.common.entity.CharRoomMessage;
import io.kimmking.dubbo.common.mapper.CharRoomMessageMapper;
import io.kimmking.dubbo.common.service.CharRoomMessageService;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;

@DubboService(version = "1.0.0", interfaceClass = CharRoomMessageService.class)
public class CharRoomMessageServiceImpl extends ServiceImpl<CharRoomMessageMapper, CharRoomMessage>
        implements CharRoomMessageService {

    private final ProducerWrapper<CharRoomMessage> producerWrapper;

    public CharRoomMessageServiceImpl(final ProducerWrapper<CharRoomMessage> producerWrapper) {
        this.producerWrapper = producerWrapper;
    }

    @Override
    public boolean sendMessage(String topic, CharRoomMessage charRoomMessage) {
        SendResult sendResult = producerWrapper.try_sync_send_with_tag(topic,charRoomMessage.getFromCustomerName(),charRoomMessage,1000);
        return sendResult.getSendStatus() == SendStatus.SEND_OK;
    }

}